const Mock = require('mockjs')
const Random = Mock.Random;

const token = Random.guid()

// 演示用户信息admin
const userInfo = Mock.mock({
    user_id: Random.id(),
    mg_name: 'admin',
    roles: ['admin'],
    avatar: '@AVATAR',
    address: '@CITY',
    position: '@POSITION',
    login_date_time: Random.now()
})

// 通用模板API
const fastAPI = {
    // 登录
    login: (config) => {
      const { user_name, password } = config.body;
      let success = false
      if(user_name == 'admin' && password == '123123') {
        success =  true
      }
      if(success) {
        return {
            data: { token },
            code: 200,
            msg: '成功'
        };
      }else{
        return {
            code: 0,
            msg: '账户名或密码错误(admin/123123)'
        };
      }
    },
    // 获取用户信息
    getUserInfo: () => {
      return {
        data: userInfo,
        code: 200,
        msg: '成功'
      };
    },
  }

  module.exports = [
    {
      url: '/login/loginIn',
      type: 'post',
      response: fastAPI.login
    },
    {
      url: '/login/getUserInfo',
      type: 'post',
      response: fastAPI.getUserInfo
    },
  ]